import java.util.HashSet;
import java.util.Set;

public class Test1 {

    public static class ListNode{
        public Object val;
        public ListNode next;
        public ListNode(Object val){
            this.val=val;
        }
    }
    public static void main(String[] args) {

      ListNode head = new ListNode(null);
      ListNode p  =head;
        int[] arr = new int[]{1,2,3,6,6,7,8,9,9};  //哑元
        for (int i = 0; i <arr.length ; i++) {
            p.next=new ListNode(arr[i]);
            p=p.next;
        }
        ListNode head1=head.next;
        Remove(head1);
        while(head1!=null){
            System.out.println(head1.val+" ");
            head1=head1.next;
        }
    }

    private static void Remove(ListNode head) {
        Set<Object> set = new HashSet<>();
        ListNode  pre = head;
        ListNode cur = head;
        while(cur!=null){
            if(!set.contains(cur.val)){
                set.add(cur.val);
                pre=cur;
                cur=cur.next;  //这里要移动指针，然后才能进行下一步的操作

            }else{
                pre.next=cur.next;

                cur=cur.next;
            }

        }
    }
}
